<meta charset="utf-8" />
<script src="js/jquery.min.js" type="text/javascript"></script>  
<script src="js/jwplayer.js" type="text/javascript"></script>
<script src="jquery_cookie.js" type="text/javascript"></script>
<div id="container"></div>  
<input type="button" class="player-play" value="播放" />  
<input type="button" class="player-stop" value="停止" />  
<input type="button" class="player-status" value="取得状态" />  
<input type="button" class="player-current" value="当前播放秒数" />  
<input type="button" class="player-goto" value="转到第30秒播放" />  
<input type="button" class="player-length" value="视频时长(秒)" /> 
<script type="text/javascript">jwplayer.key="KVSnE/FWc+VUcBX1hZEJYJ10DI/3yNV5wTPG/w==";</script>
<script type="text/javascript">  
    var thePlayer;  //保存当前播放器以便操作  
    $(function() {  
        thePlayer = jwplayer('container').setup({  
            flashplayer: 'player.swf',  
            //file: 'http://121.42.61.20/7854.mp4',
            file: '7833.mp4', 
            width: 500, 
            height: 350,
            dock: false,
            stretching : 'fill',
            streamer: "start",//这俩行必须要写，这样才能随时跳转，实现伪流的功能,要不不能实现在缓冲数据后面进行拖拽。如果不能随意拖拽进度条，说明你得nginx伪流搭建不成功
            provider: "http",
            events: {
                //onComplete: function () { console.log("播放结束!!!"); },
                onComplete: function () {thePlayer.seek($.cookie("time11",''))},
                onVolume: function () { console.log("声音大小改变!!!"); },
                onReady: function () { console.log("准备就绪!!!"); },
                //开始时  读取历史记录
                onPlay: function () {thePlayer.seek($.cookie("time11"))},
                //暂停时 记录位置
                onPause: function () {$.cookie("time11",thePlayer.getPosition())}, 
                onBufferChange: function () { console.log("缓冲改变!!!"); },
                onBufferFull: function () { console.log("视频缓冲完成!!!"); },
                onError: function (obj) { console.log("播放器出错!!!" + obj.message); },
                onFullscreen: function (obj) { if (obj.fullscreen) { console.log("全屏"); } else { console.log("非全屏"); } },
                onMute: function (obj) { console.log("静音/取消静音") }
            }
        });    
        //播放 暂停  
        $('.player-play').click(function() {  
            if (thePlayer.getState() != 'PLAYING') {  
                thePlayer.play(true);  
                this.value = '暂停';  
            } else {  
                thePlayer.play(false);  
                this.value = '播放';  
            }  
        });  
          
        //停止  
        $('.player-stop').click(function() { thePlayer.stop(); });  
          
        //获取状态  
        $('.player-status').click(function() {  
            var state = thePlayer.getState();  
            var msg;  
            switch (state) {  
                case 'BUFFERING':  
                    msg = '加载中';  
                    break;  
                case 'PLAYING':  
                    msg = '正在播放';  
                    break;  
                case 'PAUSED':  
                    msg = '暂停';  
                    break;  
                case 'IDLE':  
                    msg = '停止';  
                    break;  
            }  
            alert(msg);  
        });  
          
        //获取播放进度  
        $('.player-current').click(function() { alert(thePlayer.getPosition()); });  
  
        //跳转到指定位置播放  
        $('.player-goto').click(function() {  
            if (thePlayer.getState() != 'PLAYING') {    //若当前未播放，先启动播放器  
                thePlayer.play();
            }  
            thePlayer.seek(30); //从指定位置开始播放(单位：秒)  
        });  
          
        //获取视频长度  
        $('.player-length').click(function() { alert(thePlayer.getDuration()); });
        
        
    });

    //页面关闭时记录播放位置
    window.onbeforeunload = function(event) { 
        var state = thePlayer.getState();
        if (state == 'PLAYING') {
            $.cookie("time11",thePlayer.getPosition())
        }
    }
</script>  